package com.example.yls.demoa;

import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.BottomSheetDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.CollapsibleActionView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    private LinearLayout bottomSheet;
    private BottomSheetBehavior<LinearLayout> bottomSheetBehavior;
    private boolean isOpen = false;
    private BottomNavigationBar bottomNavigationBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        bottomSheet = findViewById(R.id.bottom_sheet);
        bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);

        bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                Log.e(TAG,"newState = " + newState);
            }

            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {
                Log.e(TAG,"slideOffset = " + slideOffset);
            }
        });
        findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                initBottomNacigationBar();
//                new MyBottomSheetDialogFragment().show(getSupportFragmentManager(),"poem");

                /**BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(MainActivity.this);
                bottomSheetDialog.setContentView(R.layout.poem);
                bottomSheetDialog.show();
                 */

                /**if(isOpen){
                    bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
                }else {
                    bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
                }
                isOpen = !isOpen;
                 */
            }
        });
        findViewById(R.id.tv1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this,"TV 1 Click",Toast.LENGTH_SHORT).show();
            }
        });
        findViewById(R.id.tv2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this,"TV 2 Click",Toast.LENGTH_SHORT).show();
            }
        });
        findViewById(R.id.tv3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this,"TV 3 Click",Toast.LENGTH_SHORT).show();
            }
        });
        findViewById(R.id.tv4).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this,"TV 4 Click",Toast.LENGTH_SHORT).show();
            }
        });
    }
    private void initBottomNacigationBar(){
        bottomNavigationBar = findViewById(R.id.id_bnb);
        bottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.up,"A")
                .setActiveColor(Color.RED));
        bottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.up,"B")
                .setActiveColor(Color.GREEN));
        bottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.up,"C")
                .setActiveColor(Color.BLUE));
        bottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.up,"D")
                .setActiveColor(Color.YELLOW));
        bottomNavigationBar.initialise();

        bottomNavigationBar.setTabSelectedListener(new BottomNavigationBar.SimpleOnTabSelectedListener(){
            @Override
            public void onTabSelected(int position) {
                super.onTabSelected(position);
                switch (position){
                    case 0:
                        Toast.makeText(MainActivity.this,"A",Toast.LENGTH_SHORT).show();
                        break;
                    case 1:
                        Toast.makeText(MainActivity.this,"B",Toast.LENGTH_SHORT).show();
                        break;
                    case 2:
                        Toast.makeText(MainActivity.this,"C",Toast.LENGTH_SHORT).show();
                        break;
                    case 3:
                        Toast.makeText(MainActivity.this,"D",Toast.LENGTH_SHORT).show();
                        break;
                }
            }

            @Override
            public void onTabReselected(int position) {
                super.onTabReselected(position);
            }

            @Override
            public void onTabUnselected(int position) {
                super.onTabUnselected(position);
            }
        });
    }
}
